gsk: Add font options to the glyph cache
authorMatthias Clasen <mclasen@redhat.com>
Wed, 1 Sep 2021 03:01:43 +0000 (23:01 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 3 Sep 2021 16:52:05 +0000 (12:52 -0400)
The cairo_t that we create to render glyphs for
the glyph cache needs to match the font options
that are supposedly governing how glyphs are
drawn.

Since we allow font options to be different per
widget in gtk, we need to have them at least at
the level of individual render nodes. Adding them
to the lookup key for the glyph cache has the
side effect of solving another problem: We are
not flushing the cache when font options change.

gsk/ngl/gsknglglyphlibrary.c
gsk/ngl/gsknglglyphlibraryprivate.h

index 9f269d8643d5aac4a8bd318f55d6ef9ae5a96bb7..fdfa1abe3021baa28fab4647e75e305b038362ef 100644 (file)
@@ -166,11 +166,19 @@ render_glyph (cairo_surface_t           *surface,
 {
   cairo_t *cr;
   cairo_glyph_t glyph;
+  cairo_font_options_t *options;
 
   g_assert (surface != NULL);
   g_assert (scaled_font != NULL);
 
   cr = cairo_create (surface);
+  options = cairo_font_options_create ();
+  cairo_font_options_set_hint_metrics (options, key->hint_metrics ? CAIRO_HINT_METRICS_ON : CAIRO_HINT_METRICS_OFF);
+  cairo_font_options_set_antialias (options, key->antialias ? CAIRO_ANTIALIAS_GRAY : CAIRO_ANTIALIAS_NONE);
+  cairo_font_options_set_hint_style (options, key->hint_style);
+  cairo_set_font_options (cr, options);
+  cairo_font_options_destroy (options);
+
   cairo_set_scaled_font (cr, scaled_font);
   cairo_set_source_rgba (cr, 1, 1, 1, 1);
 
index a9f099c0b5dface8ac2d310649b551f97657d73e..6d9e81060e8ee27a52f4c5ff4d6fed27d6ec8e78 100644 (file)
@@ -35,7 +35,10 @@ typedef struct _GskNglGlyphKey
   PangoGlyph glyph;
   guint xshift : 2;
   guint yshift : 2;
-  guint scale  : 28; /* times 1024 */
+  guint hint_metrics : 1;
+  guint antialias : 1;
+  guint hint_style : 3;
+  guint scale  : 23; /* times 1024 */
 } GskNglGlyphKey;
 
 typedef struct _GskNglGlyphValue